import com.beans.UserBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-10-09
 * Time:21:05
 */
public class App {
    public static void main(String[] args) {
//        //1、得到spring的上下文，与resources xml配置文件名字保持一致
//        ApplicationContext context=
//                new ClassPathXmlApplicationContext("spring-config.xml");
//        //2、根据上下文对象提供的方法获取到Bean,参数与xml中id名保持一致
//        UserBean user=(UserBean) context.getBean("userBean");
//
//        //3、使用
//        user.sayHi("张嘉庆");

        //1、获取bean工厂
        BeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));

        //2、获取bean
        UserBean user = (UserBean) factory.getBean("userBean");

        //3、使用
        user.sayHi("李四");
    }
}
